package com.wtb.thread;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wtb.domain.DataCache;
import com.wtb.pub.WtbException;
import com.wtb.rr.domain.RrOauth;

public class RrTraverThread implements Runnable{
	private static final Log log = LogFactory.getLog(RrTraverThread.class);
	private BlockingQueue<RrOauth> traver_rrQueue;			//人人状态遍历队列
	public RrTraverThread(BlockingQueue<RrOauth> traver_rrQueue){
		this.traver_rrQueue = traver_rrQueue;
	}
	@SuppressWarnings("unchecked")
	public void run() {
		log.info(Thread.currentThread().getName()+"--已启动");
		HashMap<String,RrOauth> rrMap = DataCache.synRrMap();
		Collection<RrOauth> rrCollection;
		RrOauth rrOauth;
		while (rrMap != null) {
			log.debug(Thread.currentThread().getName()+"在工作！");
			rrCollection = rrMap.values();
			for (Iterator<RrOauth> iterator = rrCollection.iterator(); iterator.hasNext();) {
				rrOauth = iterator.next();
				try {
					if (rrOauth.getR2q().equals("1")) {
						traver_rrQueue.put(rrOauth);
					}
				} catch (InterruptedException e) {
					log.error("放入RR读取队列失败：", e);
					throw new WtbException("放入RR读取队列失败", e);
				}
			}
			try {
				log.debug("人人遍历线程在休息！");
				Thread.sleep(1000*60);
			} catch (InterruptedException e) {
			}
			rrMap = DataCache.synRrMap();
		}
	}

}
